package com.ruoyi.web.controller.grape;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.grape.domain.GrapeOrchard;
import com.ruoyi.grape.service.IGrapeOrchardService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 园区基本信息Controller
 * 
 * @author ld
 * @date 2023-11-18
 */
@RestController
@RequestMapping("/grape/orchard")
public class GrapeOrchardController extends BaseController
{
    @Autowired
    private IGrapeOrchardService grapeOrchardService;

    /**
     * 查询园区基本信息列表
     */
    @PreAuthorize("@ss.hasPermi('grape:orchard:list')")
    @GetMapping("/list")
    public TableDataInfo list(GrapeOrchard grapeOrchard)
    {
        startPage();
        List<GrapeOrchard> list = grapeOrchardService.selectGrapeOrchardList(grapeOrchard);
        return getDataTable(list);
    }

    /**
     * 导出园区基本信息列表
     */
    @PreAuthorize("@ss.hasPermi('grape:orchard:export')")
    @Log(title = "园区基本信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GrapeOrchard grapeOrchard)
    {
        List<GrapeOrchard> list = grapeOrchardService.selectGrapeOrchardList(grapeOrchard);
        ExcelUtil<GrapeOrchard> util = new ExcelUtil<GrapeOrchard>(GrapeOrchard.class);
        util.exportExcel(response, list, "园区基本信息数据");
    }

    /**
     * 获取园区基本信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('grape:orchard:query')")
    @GetMapping(value = "/{orchardId}")
    public AjaxResult getInfo(@PathVariable("orchardId") Long orchardId)
    {
        return success(grapeOrchardService.selectGrapeOrchardByOrchardId(orchardId));
    }

    /**
     * 新增园区基本信息
     */
    @PreAuthorize("@ss.hasPermi('grape:orchard:add')")
    @Log(title = "园区基本信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GrapeOrchard grapeOrchard)
    {
        return toAjax(grapeOrchardService.insertGrapeOrchard(grapeOrchard));
    }

    /**
     * 修改园区基本信息
     */
    @PreAuthorize("@ss.hasPermi('grape:orchard:edit')")
    @Log(title = "园区基本信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GrapeOrchard grapeOrchard)
    {
        return toAjax(grapeOrchardService.updateGrapeOrchard(grapeOrchard));
    }

    /**
     * 删除园区基本信息
     */
    @PreAuthorize("@ss.hasPermi('grape:orchard:remove')")
    @Log(title = "园区基本信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{orchardIds}")
    public AjaxResult remove(@PathVariable Long[] orchardIds)
    {
        return toAjax(grapeOrchardService.deleteGrapeOrchardByOrchardIds(orchardIds));
    }
}
